//
//  MBDUserInfoViewModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/23.
//

import Foundation


import UIKit
import Kingfisher

class MBDUserDetailCellModel : MBDCommonCellModel {
    var itemName : String?
    
    var detailText : String?
    var detailImageURLString : String?

    private var detailType : MBDDetailType?

    var accessable : Bool?
    var location : MBDCellLocation?
    
    func isEmpty() -> Bool {
        return detailText == MBDDetailUserNameCellModel.setUserName
    }
}

class MBDUserDetailAvatarCellModel : MBDUserDetailCellModel {
    
}

class MBDUserDetailUserNameCellModel : MBDUserDetailCellModel {
    
}

class MBDUserDetailWechatNumCellModel : MBDUserDetailCellModel {
    
}

class MBDUserInfoViewModel : NSObject {
    @objc dynamic var cellModels : Array<MBDUserDetailCellModel>?
    var params : Dictionary<String, Any>?
    
    var realName : String?
    var userId : String?
    var avatarUrl : String?
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(params : Dictionary<String, Any>) {
        super.init()
        
        self.params = params
        
        if let rn = params["realName"] {
            self.realName = rn as? String
        }
        
        if let au = params["avatarURL"] {
            self.avatarUrl = au as? String
        }
        
        if let ui = params["userId"] {
            self.userId = ui as? String
        }

    }
    
    static func defaultCellModels(realName : String,avatar : String) -> Array<MBDUserDetailCellModel>{
        var cellModels = Array<MBDUserDetailCellModel>()
        
        let avatarCellModel = MBDUserDetailAvatarCellModel()
        
        avatarCellModel.itemName = "头像"
        avatarCellModel.location = .top
        avatarCellModel.detailImageURLString = avatar
        //

        cellModels.append(avatarCellModel)
        
        let nameCellModel = MBDUserDetailUserNameCellModel()
                
        nameCellModel.itemName = "用户名"
        nameCellModel.location = .center
        nameCellModel.detailText = realName

        cellModels.append(nameCellModel)
        
        return cellModels
    }
    

    func doRequest(blacklistUserId : String! ,completion : @escaping (_ error : Error?, _ result : Bool?)->()) {
        
        let para = ["blacklistUserId":String(blacklistUserId) ]

        MBDHttpClient.shared.doPostRequest("/blacklist/save",parameters: para).httpClientResponse { error, response in
            completion(error,error == nil)
        }
    }
    
}
